#include "moveButton.h"
#include "input.h"


MoveButton::MoveButton()
{
bActive=false;
name="LOCATION";
//fineLocation=Vector3f(0,0,0);
}

void MoveButton::update(double deltaTime)
{
    if (bActive && parent)
      {
          if (parent==input->controller){
                  Vector3f loc=parent->location;

                  input->controller->confineMouse();
                  if (input->bShiftDown){
                    fineLocation[0].y+=input->mouseVector.y*0.1;
                    loc.y=fineLocation[0].y;
                  }
                  else if (input->bCtrlDown)
                  {
                    fineLocation[0].x+=input->mouseVector.x*0.1;
                    loc.x=fineLocation[0].x;
                  }
                  else{
                      fineLocation[0].z-=input->mouseVector.y*0.1;
                      loc.z=fineLocation[0].z;
                  }

                  parent->setLocation(loc);
          }
          else{

            for (int i=0;i<(int)input->selectedActors.size();i++){

                  Vector3f loc=input->selectedActors[i]->location;

                  input->controller->confineMouse();
                  if (input->bShiftDown){
                    fineLocation[i]+=Vector3f(0.0, input->mouseVector.y*0.1, 0.0);
                    loc=fineLocation[i];
                  }
                  else
                    {
                    fineLocation[i]+=Vector3f(0.0, 1.0, 0.0).crossProduct(input->controller->orientation) *   input->mouseVector.x*0.1;
                    fineLocation[i]-=Vector3f(input->controller->orientation.x, 0.0, input->controller->orientation.z) * input->mouseVector.y*0.1;
                    loc=fineLocation[i];
                    }
                  //don't do it twice!
                    input->selectedActors[i]->setLocation(loc);
            }
          }
      }
}


void MoveButton::create()
{
renderer->addButton(this);
std::cout << "creating a MoveButton!";
}
